<?php
	$id=$_GET["edit"];
	$db=new DB();
	$query ="Select * from reservaciones where Id_Reservacion='{$id}'";
	$r=$db->query($query);
	if($db->total()>0){
		$row=$db->getRow();
		$ResValues= array("{$row[8]}","{$row[7]}","{$row[9]}","{$row[10]}","{$row[11]}","{$row[12]}",
						  "{$row[13]}","{$row[14]}","{$row[15]}","{$row[16]}","{$row[17]}","{$row[1]}","{$row[2]}","{$row[3]}");
	}
	$db->close();
?>
<script language="javascript" src="../js/operadoraLib.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript" src="../js/calendar.js" ></script>
<script type="text/javascript" src="../js/calendar-es.js" language="javascript"></script>
<script type="text/javascript" src="../js/calendar-setup.js" language="javascript"></script>
<style type="text/css">@import url(../css/calendar.css);</style>
<form name="EditRes" method="post" action="ReservacionesV.php">
<input type="hidden" name="editedId" value="<?php echo $id; ?>" />
<table border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
    	<td class="formtitle" colspan="4">Editar Reservaci&oacute;n</td>
    </tr>
    <tr>
    	<td class="formLabelRes">Titulo Cliente</td>
  <td width="179" class="formInput">
       	<input type="text" name="TCliente" id="TCliente" size="4" maxlength="5" value="<?php echo $ResValues[0];  ?>" />
        </td>
      <td class="formLabelRes">Nombre Cliente</td>
      <td class="formInput"><input type="text" name="NCliente" id="NCliente" size="20" value="<?php echo $ResValues[1];  ?>" /></td>
    </tr>
    <tr>
    	<td class="formLabelRes">Hotel</td>
        <td class="formInput" style="white-space:nowrap;">
			<?php 
				$db=new DB();
                $query="Select Id_Hotel,Id_Destino,Nombre_Destino from Destino";
                $result=$db->query($query);
				echo "<script language='javascript'>
					  var destinosArr = new Array();
					  var yDimencion = ".$db->total().";";
				$z=0;
				while($row=$db->getRow()){
					echo "destinosArr[{$z}]=new Array();
						  destinosArr[{$z}][0]={$row[0]};
						  destinosArr[{$z}][1]={$row[1]};
						  destinosArr[{$z}][2]='{$row[2]}';";
					$z++;
				}
				$db->close();
				$db=new DB();
				$r=$db->query("Select h.Id_Hotel,t.Id_Tipo, t.Nombre from tipo_habitacion t Inner Join habitaciones h 
								on t.Id_Tipo=h.Id_Tipo");
				$z=0;
				echo "habitacionesArr = new Array();";
				while($row=$db->getRow()){
					echo "habitacionesArr[{$z}]=new Array();
						  habitacionesArr[{$z}][0]={$row[0]};
						  habitacionesArr[{$z}][1]={$row[1]};
						  habitacionesArr[{$z}][2]='{$row[2]}';";
					$z++;
				}
				$db->close();
                echo "</script>";
                $db=new DB();
                $query="Select Id_Hotel,Nombre from hoteles";
                $result=$db->query($query);
                echo "<select name='Hoteles' onChange='populateDestinos(Hoteles[Hoteles.selectedIndex].value, destinosArr, document.EditRes.Destinos); populateDestinos(Hoteles[Hoteles.selectedIndex].value, habitacionesArr, document.EditRes.tHabitaciones);'>";
                if($db->total()>0){
                    while($row=$db->getRow()){
						if($row[0]==$ResValues[12]){
							echo "<option value='{$row[0]}' selected>{$row[1]}</option>";
						}else{
	                        echo "<option value='{$row[0]}'>{$row[1]}</option>";
						}
                    }
                }
                echo "</select>";
				$db->close();
				
            ?>
        </td>
        <td class="formLabelRes">Destino</td>
        <td class="formInput" style="white-space:nowrap;">
        	<select name="Destinos">
            	<?php
            	$db=new DB();
                $query="Select Id_Destino,Nombre_Destino from Destino where Id_Destino='{$ResValues[11]}'";
                $result=$db->query($query);
                if($db->total()>0){
                    while($row=$db->getRow()){
						echo "<option value='{$row[0]}'>{$row[1]}</option>";
                    }
                }
                $db->close();
				?>
            </select>
        </td>
    </tr>
     <tr>
    	<td class="formLabelRes">Tipo de Habitaci&oacute;n</td>
        <td class="formInput" style="white-space:nowrap;">
        	<select name="tHabitaciones">
            	<?php
            	$db=new DB();
                $query="Select * from tipo_habitacion where Id_Tipo='{$ResValues[13]}'";
                $result=$db->query($query);
                if($db->total()>0){
                    while($row=$db->getRow()){
						echo "<option value='{$row[0]}'>{$row[1]}</option>";
                    }
                }
                $db->close();
				?>
            </select>
        </td>
        <td class="formLabelRes">&nbsp;</td>
        <td class="formInput">&nbsp;</td>
    </tr> 
    <tr>
    	<td class="formLabelRes">Fecha Reservaci&oacute;n</td>
        <td class="formInput" style="white-space:nowrap;">
        	<input type="text" name="FRes" id="FRes" value="<?php echo $ResValues[2]; ?>" size="11" readonly />
        	<img style="vertical-align:middle;" class="btnCalendar" src="../images/calendar.jpg" id="FRestrigger" onMouseOver="this.style.border='1px outset #000000';" onMouseOut="this.style.border='1px outset #CCCCCC';" />
            <script type="text/javascript">
				Calendar.setup(
					{
						inputField : "FRes", // ID of the input field
						ifFormat : "%Y-%m-%d", // the date format
						button : "FRestrigger" // ID of the button
					}
				);
			</script>
        </td>
        <td class="formLabelRes">Fecha limite para agencia</td>
        <td class="formInput">
        	<input type="text" name="FLim" id="FLim" value="<?php echo $ResValues[3]; ?>" size="11" readonly />
            <img style="vertical-align:middle;" class="btnCalendar" src="../images/calendar.jpg" id="FLimtrigger" onMouseOver="this.style.border='1px outset #000000';" onMouseOut="this.style.border='1px outset #CCCCCC';" />
            <script type="text/javascript">
				Calendar.setup(
					{
						inputField : "FLim", // ID of the input field
						ifFormat : "%Y-%m-%d", // the date format
						button : "FLimtrigger" // ID of the button
					}
				);
			</script>
        </td>
    </tr>
    <tr>
    	<td class="formLabelRes">N&deg; Noches</td>
        <td class="formInput"><input size="7" type="text" name="noches" id="noches" value="<?php echo $ResValues[10]; ?>" /></td>
    	<td class="formLabelRes">Tipo Pago</td>
        <td class="formInput"><select name="TPago" id="TPago">
        	<?php
				$posPagos= array("Efectivo","Tarjeta","Cheque","Deposito","Otro");
				for($z=0;$z<5;$z++){
					if($posPagos[$z]==$ResValues[4]){
						echo "<option value='".$posPagos[$z]."' selected>".$posPagos[$z]."</option>";
					}else{
						echo "<option value='".$posPagos[$z]."'>".$posPagos[$z]."</option>";
					}
				}
			?>
        	</select>
        </td>
    </tr>
    <tr>
    	<td class="formLabelRes">Costo</td>
        <td class="formInput"><input size="7" type="text" name="Costo" id="Costo" value="<?php echo $ResValues[5]; ?>" /></td>
    	<td class="formLabelRes">Saldo</td>
        <td class="formInput"><input size="7" type="text" name="Saldo" id="Saldo" value="<?php echo $ResValues[6]; ?>" /></td>
    </tr>
    <tr>
    	<td class="formLabelRes" valign="top">Solicitud Especial</td>
        <td colspan="3" class="formInput">
        	<textarea rows="2" cols="60" name="SolEsp" id="SolEsp"><?php echo $ResValues[7]; ?></textarea>
        </td>
    </tr>
    <tr>
    	<td class="formLabelRes">&nbsp;</td>
        <td class="formInput">&nbsp;</td>
        <td class="formLabelRes">Factura</td>
        <td class="formInput"><select name="Factura" id="Factura">
        	<?php
				$factura= array("Si","No");
				for($z=0;$z<5;$z++){
					if($factura[$z]==$ResValues[9]){
						echo "<option value='".$factura[$z]."' selected>".$factura[$z]."</option>";
					}else{
						echo "<option value='".$factura[$z]."'>".$factura[$z]."</option>";
					}
				}
			?>
        	</select></td>
    </tr>
    <tr>
    	<td colspan="4" align="center">
        	<br />
            <input type="button" name="CancelarBtn" value="Cancelar" onClick="parent.location.replace('ReservacionesV.php')" />
        	<input type="submit" name="ActualizarBtn" value="Actualizar" />
        </td>
    </tr>
</table>
</form>